package com.xxx.mall.api.platform;

import com.xxx.mall.dto.BrandDTO;
import com.xxx.mall.dto.BrandQuery;
import com.xxx.mall.dto.PageQuery;
import com.xxx.mall.group.Add;
import com.xxx.mall.group.Update;
import com.xxx.mall.response.R;
import com.xxx.mall.service.BrandService;
import com.xxx.mall.vo.BrandVO;
import com.xxx.mall.vo.PageVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 品牌信息 前端控制器
 * </p>
 *
 * @author 邢晨旭
 * @since 2023-11-15
 */
@RestController("platformBrandController")
@RequestMapping("/platform/brand")
public class BrandApi {

    @Resource
    BrandService brandService;

    @GetMapping("/page")
    public R<PageVO<BrandVO>> page(@Valid PageQuery pageQuery, BrandQuery brandQuery) {
        return R.ok(brandService.pageList(pageQuery, brandQuery));
    }

    @PostMapping
    public R<Void> save(@RequestBody @Validated(Add.class) BrandDTO brandDTO) {
        brandService.saveBrand(brandDTO);
        return R.ok();
    }

    @PutMapping
    public R<Void> update(@RequestBody @Validated(Update.class) BrandDTO brandDTO) {
        brandService.updateBrand(brandDTO);
        return R.ok();
    }

    @GetMapping("/{id}")
    public R<BrandVO> getById(@PathVariable("id") Long brandId) {
        return R.ok(brandService.queryById(brandId));
    }

    @DeleteMapping("/{id}")
    public R<Void> deleteById(@PathVariable("id") Long brandId) {
        brandService.deleteById(brandId);
        return R.ok();
    }

}
